<template>
  <basic-container>
    <avue-crud
      ref="crud"
      :page.sync="page"
      :table-loading="tableLoading"
      :data="tableData"
      :option="tableOption"
      @on-load="getList"
      @refresh-change="refreshChange"
      @size-change="sizeChange"
      @current-change="currentChange"
    ></avue-crud>
  </basic-container>
</template>

<script>
import {getTableColumn} from "@/api/gen/generator";
import {tableColumnOption} from "./generator";

export default {
  name: "tableColumnInfo",
  props: {
    queryData: {}
  },
  data() {
    return {
      tableLoading: false,
      tableData: [],
      tableOption: tableColumnOption,
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      }
    };
  },
  methods: {
    getList(page) {
      this.tableLoading = true;
      getTableColumn(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          this.queryData
        )
      )
        .then(response => {
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    },
    refreshChange() {
      this.getList(this.page);
    }
  }
};
</script>
